let fs = require('fs')
let command = require('./lib/command')
let loadCmds = require('./lib/loadcmd')(command.loadPath)
let exec = require('./lib/ssh')

let conns = JSON.parse(fs.readFileSync(command.configPath, 'utf-8')).conns

if(command.order){
    // await
    ;(function bloc() {
        let conn = conns.shift()
        if (conn !== undefined) {   
            exec
            .execShell(conn, loadCmds(!conn.isroot), command.level)
            .then(bloc)  
        }
    }())
}else{
    //async
    conns.forEach(function(v) {
        exec
        .execShell(v, loadCmds(!v.isroot), command.level)
    })
}